define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_integral_red_log/index' + location.search,
                    add_url: 'user_integral_red_log/add',
                    //edit_url: 'luckydrawdetail/edit',
                    //del_url: 'luckydrawdetail/del',
                    multi_url: 'user_integral_red_log/multi',
                    import_url: 'user_integral_red_log/import',
                    table: 'user_integral_red_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'userId', title: __(' 用户id')},
                        {field: 'userhome.nickname', title: __('昵称'),operate: 'LIKE'},
                        {field: 'userhome.phone', title: __('用户手机号'),operate: 'LIKE'},
                        {field: 'redNum', title: __('红包金额')},
                        {field: 'status', title: __('类型'), searchList: {'ENTER' : '已入账 ', 'WAIT' :'待入账', 'PAST' : '已过期'}, formatter: Table.api.formatter.normal},
                        {field: 'createTime', title: __('兑换时间'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'break', title: __('备注'), operate: false},
                        
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                //commonSearch: false,//通用搜索
                showToggle: false,//显示隐藏列可以快速切换字段列的显示和隐藏，如果不需要此功能，可以设置showColumns: false，如果想要表格中的字段列默认隐藏可以设置字段属性visible: false即可默认隐藏
                showColumns: false,//导出按钮默认将导出整个表的所有行
                showExport: false,//导出excel
                search:false,//快速搜索
            });


            $("#exp").bind("click",function(){
                var options = table.bootstrapTable('getOptions');
                var search = options.queryParams({});
                var str=location.search+"&filter="+search.filter+"&op="+search.op;
                window.location.href = 'user_integral_red_log/export'+str  ;
            });



            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});